<?php

/**
 * 各服务页面
*/

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');

if ((DEBUG_MODE & 2) != 2)
{
    $smarty->caching = true;
}
if(empty($_SESSION['user_id']))
{
	ecs_header("Location:user.php");
}
$type   =  isset($_REQUEST['type'])   ? trim($_REQUEST['type'])   : "";
$source =  isset($_REQUEST['source']) ? trim($_REQUEST["source"]) : "mba";
$act = $_REQUEST['act'];
if(empty($type))
{
	ecs_header("Location:index.php");
}
if($act == "modify")
{
	$id = intval($_REQUEST['id']);
	$sql = "SELECT * FROM " . $ecs->table("cart") . " WHERE rec_id = '{$id}' AND session_id = '".SESS_ID."'";
	$cart_info = $db->getRow($sql);
	$smarty->assign("cart_info" , $cart_info);
	$smarty->assign("act" , "update");
	$source = $cart_info["source"];
}
assign_template();
$info = get_service_info($type);
$smarty->assign("info" , $info);
$smarty->assign("type" , $type);
$smarty->assign("source" , $source);
$page = $type.".dwt";
$smarty->display($page);
/**
 * 服务详情
 *
 * @param str $type
 * @return arr
 */

function get_service_info($type)
{
	$sql = "SELECT * FROM " . $GLOBALS["ecs"]->table("service") . " WHERE type = '{$type}'";
	$info = $GLOBALS['db']->getRow($sql);
	
	if($type == "essay" || $type == "chenshu")
	{
		$info["price"] = @unserialize($info['price']);
		$info["minletter"] = @unserialize($info["minletter"]);
		$info["maxletter"] = @unserialize($info["maxletter"]);
	}
	
	if($type == "quiz" || $type == "multiple")
	{
		$info["timelist"] = @unserialize($info['timelist']);
		$info["number"] = @unserialize($info["number"]);
		foreach($info['timelist'] AS $key => $val)
		{
			$number = checkTimeStorage($val, $type);
			if($number >= $info["number"][$key])
			{
				unset($info["timelist"][$key]);
			}
		}
	}
	return $info;
}
?>